package com.example.yuejian21.nongfusanquan.yuejian21.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yuejian21.nongfusanquan.yuejian21.R;
import com.squareup.picasso.Picasso;

/**
 * Created by Nongfusanquan on 2017-10-13.
 */

public class CoursedetailActivity extends AppCompatActivity{
    private TextView courseintro,coursetime,courseaddr,coursename;
    private ImageView coursepic;
    private Button back,order;
    private int u_id;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coursedetail);
        SharedPreferences sharePreferences = this.getBaseContext().getSharedPreferences("cache", Context.MODE_PRIVATE);
        String i = sharePreferences.getString("uid",null);
        u_id = Integer.parseInt(i);
        initViews();
        initEvent();
        getData();
    }

    private void initViews(){
        coursename=(TextView)findViewById(R.id.coursedetail_name);
        courseintro=(TextView)findViewById(R.id.courseintro);
        coursetime=(TextView)findViewById(R.id.courseaddr);
        courseaddr=(TextView)findViewById(R.id.coursetime);
        back=(Button)findViewById(R.id.return_coursedetail);
        coursepic=(ImageView)findViewById(R.id.coursedetail_pic);
        order=(Button)findViewById(R.id.order);
    }

    private void initEvent(){
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
             finish();

            }
        });

        Bundle bundle = this.getIntent().getExtras();
        final int t_id=bundle.getInt("t_id");
        order.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(CoursedetailActivity.this, OrderCourseActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("t_id", t_id);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });


    }
    private void getData() {
        Bundle bundle = this.getIntent().getExtras();
        String tname = bundle.getString("t_name");
        String taddress = bundle.getString("t_address");
        String tintro =bundle.getString("t_info");
        String tpicture = "http://10.0.2.2/yuejian14/Public/Admin/trainpicture/"+bundle.getString("t_picture");

        String ttime = bundle.getString("t_time");
        coursename.setText(tname);
        courseaddr.setText(taddress);
        courseintro.setText(tintro);


        coursetime.setText(ttime);
        Picasso.with(this).load(tpicture).into(coursepic);
    }

}
